import { isValid, PageView } from "cc";
import { Observable } from "rxjs";

export function CCBindPageView(pageView: PageView): Observable<{ state: string, target: PageView }> {
    return new Observable((observer) => {
        let scrolling = () => {
            observer.next({ state: 'scrolling', target: pageView });
        }
        pageView.node.on('scrolling', scrolling, this);
        return () => {
            if (isValid(pageView.node)) pageView.node.off('scrolling', scrolling);
        }
    });
};